package com.md.fragment


import android.os.Bundle
import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.md.adapter.TeacherAdapter
import com.md.base.BaseFragment
import com.md.nohttp.Params
import com.md.yleducationsupervisor.R
import com.scwang.smartrefresh.layout.api.RefreshLayout
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener
import kotlinx.android.synthetic.main.fragment1.*
import kotlinx.android.synthetic.main.layout_list.*

/**
 * A simple [Fragment] subclass.
 */
class F1Fragment : BaseFragment() {
    private var teacheradadapter: TeacherAdapter? = null
    override fun setMenuVisibility(menuVisible: Boolean) {
        // TODO Auto-generated method stub
        super.setMenuVisibility(menuVisible)
        if (this.view != null) {
            this.view!!.visibility = if (menuVisible) View.VISIBLE else View.GONE
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment1, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        init()
    }

    fun init() {
        tablayout_mo.addTab(tablayout_mo.newTab().setText("平台直属"))
        tablayout_mo.addTab(tablayout_mo.newTab().setText("影子老师"))
        tablayout_mo.addTab(tablayout_mo.newTab().setText("家教"))
        tablayout_mo.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
            override fun onTabReselected(tab: TabLayout.Tab?) {
            }

            override fun onTabUnselected(tab: TabLayout.Tab?) {
            }

            override fun onTabSelected(tab: TabLayout.Tab?) {
                when (tab?.position) {
                    0 -> {

                    }
                    1 -> {

                    }
                }
            }
        })


        linearLayoutManager = LinearLayoutManager(activity)
        recycle_list.layoutManager = linearLayoutManager
        teacheradadapter = TeacherAdapter(activity, R.layout.item_teacher, Params.datas)
        recycle_list.adapter = teacheradadapter
        smart.setOnLoadMoreListener {
            object : OnRefreshLoadMoreListener {
                override fun onLoadMore(refreshLayout: RefreshLayout) {
                    smart.finishLoadMore()
                }

                override fun onRefresh(refreshLayout: RefreshLayout) {
                    smart.finishRefresh()
                }
            }
        }
    }

}
